#ifndef TCPACCEPTOR_H
#define TCPACCEPTOR_H

#include "core_global.h"
#include <boost/noncopyable.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/function.hpp>

class TcpAcceptor : protected boost::noncopyable
{
public:
    typedef boost::asio::io_service ServiceImpl;
    typedef boost::asio::ip::tcp::acceptor Acceptor;
    typedef boost::asio::ip::tcp::endpoint Endpoint;
    typedef boost::asio::ip::address Address;
    typedef boost::system::error_code ErrorCode;

    typedef boost::function< void (int) > AcceptHandler;

public:
    TcpAcceptor(ServiceImpl &service);
    ~TcpAcceptor();

    int  open(const std::string &host, unsigned short port, int listenCount);
    void close();

    void accept(Socket &sock, BOOST_ASIO_MOVE_ARG(AcceptHandler) handler);

protected:
    void onAccepted(ErrorCode ec, AcceptHandler handler);

private:
    Acceptor m_acceptor;
};

#endif // TCPACCEPTOR_H
